% script that illustrates how to postprocess the rat heart data
% make sure you set the right base and subdirs for either T1 or T2 analysis
% For questions: Henk Smit h.smit@erasmusmc.nl 
% Use ctrl+enter to execute only the currently yellow part (from %% to %%)

%% Set the base directory where the T2 rats scans are located

basedir = 'C:\Users\Henk Smit\Desktop\MRData\111025Cardiac_sensitivity_Gaby_October\PostProcessFSEs';

% Fill in the names of the T2 subdirectories, for the consecutive days:
subdirs = {
    'Prescan_Rat_0_100',
    'Prescan_Rat_1_50'};
 
% Fill in the name of the images
file = '0001';

%% Make the T2 maps for each day. 
%Choose here which subdir you want to process:
subdir = subdirs{1};
studydir = fullfile(basedir, subdir);
outdir = ratheartT2fit( studydir, file, true);
%If you want to redraw regions of interest:
%outdir = ratheartT2fit( studydir,file, true );
 
%% Select the SPIO and a myocardial region show the graphs
%Results are printed in 'results.txt' in the postproc directory of day 1
mapcolorrange = [0 1200];
ratheartdrawallspio ( basedir, subdirs, mapcolorrange );
%If you want to redraw regions of interest:
%ratheartdrawallspio ( basedir, subdirs, mapcolorrange, true );

%% Select 5 points for each day
%Choose here which subdir you want to process:
subdir = subdirs{1};
studydir = fullfile(basedir, subdir);
ratheartpointselect( studydir );

%% Start registrations; it loops automatically over all subdirs
day1studydir = fullfile(basedir, subdirs{1} );
for day = 1:numel(subdirs)
  nextdaystudydir = fullfile(basedir, subdirs{day} );
  ratheartregister( day1studydir, nextdaystudydir );
end

%% Show the final graphs of the six regions.
outdata = ratheartsegmentation( basedir, subdirs );
% outdata contains some data that you might want to inspect;

